package com.sskj.hhhjys.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.hhhjys.http.HttpConfig;
import com.sskj.hhhjys.ui.activity.PwdForgetActivity;
import com.sskj.lib.http.JsonCallBack;



public class PwdForgetActivityPresenter extends BasePresenter<PwdForgetActivity> {


    /**
     * 重置登录密码
     *
     * @param mobile 手机号/邮箱号
     * @param opwd   密码
     * @param opwd1  确认登录密码
     * @param code   验证码
     * @return
     */
    public void resetLoginPwd(String mobile, String opwd, String opwd1, String code) {
        httpService.resetLoginPwd(mobile, opwd, opwd1, code).execute(new JsonCallBack<HttpData>(this) {
            @Override
            public void onSuccess(Response<HttpData> response) {
                HttpData httpData = response.body();
                if (httpData.getStatus() == HttpConfig.OK) {
                    mView.resetPwdSuccess();
                }
            }
        });
    }

    public void sendCode(String account) {

            sendSms(account, "3");

        mView.sendCheckCodeSuccess();
    }

    /**
     * 发送验证码（注册）
     *
     * @param mobile 手机号
     * @param type   1注册 （2 重置 3 安全验证 4 交易密码设置 5 提币）
     * @return
     */
    public void sendSms(String mobile, String type) {

        httpService.sendSms(mobile, type).execute(callback);
    }

    JsonCallBack<HttpData> callback = new JsonCallBack<HttpData>(this) {
        @Override
        public void onSuccess(Response<HttpData> response) {
            HttpData httpData = response.body();
            if (httpData.getStatus() == HttpConfig.OK) {
                mView.sendCheckCodeSuccess();
            } else {
                ToastUtil.showShort(httpData.getMsg());
                mView.sendCheckCodeFail();
            }
        }

        @Override
        public void onError(Response<HttpData> response) {
            mView.sendCheckCodeFail();

            super.onError(response);
        }
    };

    /**
     * 发送邮件
     *
     * @param email 邮箱号
     * @return
     */
    public void sendEmail(String email) {
        httpService.sendEmail(email,"2").execute(callback);
    }


}
